<template>
  <div>
    <el-table :data="consultationList" border style="width: 100%">
      <el-table-column type="index" label="ID" width="50"></el-table-column>
      <el-table-column prop="title" label="问诊问题"></el-table-column>
      <el-table-column prop="created_at" label="提问时间" width="170"></el-table-column>
      <el-table-column label="操作" width="80">
        <template slot-scope="scope">
          <el-button @click="info(scope.row.id)" size="mini">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="margin-top-20 text-center" v-if="consultationList.length">
      <el-pagination
        @size-change="pageSizeChange"
        @current-change="currentPageChange"
        :background="true"
        :current-page="page.currentPage"
        :page-sizes="[10, 20, 30]"
        :page-size="page.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total">
      </el-pagination>
    </div>
  </div>
  
</template>

<script>
export default {
  data() {
    return {
      consultationList: [],
      page: {
        total: 0,
        currentPage: 1,
        size: 10
      }
    };
  },
  mounted() {
    this.getConsultationListData();
  },
  methods: {
    getConsultationListData() {
      let doctorID = this.$store.state.doctorInfo.id;
      this.axios
        .get("/doctor/" + doctorID + "/consultations/list/normal", {
          params: {
            pageSize: this.page.size,
            currentPage: this.page.currentPage,
            status: 1
          }
        })
        .then(response => {
          if (response.data.code == 200) {
            this.consultationList = response.data.data.data;
            this.page.total = response.data.data.total;
          } else {
            this.$message({
              message: "数据加载失败!",
              type: "error"
            });
          }
        });
    },
    pageSizeChange(val) {
      this.page.currentPage = 1;
      this.page.size = val;
      this.getConsultationInfoData();
    },
    currentPageChange(val) {
      this.page.currentPage = val;
      this.getConsultationInfoData();
    },
    info(id) {
      let consultationId = id;
      this.$router.push({
        name: "ReferralInfo",
        params: { consultationId: consultationId }
      });
    }
  }
};
</script>
